package com.flower.controller.admin;

import com.flower.utils.AjaxResult;
import com.flower.service.FlowerEncyclopediaService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Map;

@RestController
@RequestMapping("/admin/encyclopedia/analysis")
@RequiredArgsConstructor
@Tag(name = "花卉百科数据分析", description = "管理后台花卉百科数据分析接口")
public class EncyclopediaAnalysisController {

    private final FlowerEncyclopediaService encyclopediaService;

    @GetMapping("/overview")
    @Operation(summary = "获取花卉百科数据总览")
    public AjaxResult getOverview() {
        Map<String, Object> overview = encyclopediaService.getEncyclopediaOverview();
        return AjaxResult.success(overview);
    }

    @GetMapping("/top-views")
    @Operation(summary = "获取访问量最高的花卉百科")
    public AjaxResult getTopViewsEncyclopedias(@RequestParam(defaultValue = "10") Integer limit) {
        return AjaxResult.success(encyclopediaService.getTopViewsEncyclopedias(limit));
    }

    @GetMapping("/view-trend")
    @Operation(summary = "获取花卉百科访问量趋势")
    public AjaxResult getViewTrend(
            @RequestParam(required = false) LocalDate startDate,
            @RequestParam(required = false) LocalDate endDate,
            @RequestParam(defaultValue = "day") String timeUnit) {
        return AjaxResult.success(encyclopediaService.getEncyclopediaViewTrend(startDate, endDate, timeUnit));
    }

    @GetMapping("/category-distribution")
    @Operation(summary = "获取花卉百科分类分布")
    public AjaxResult getCategoryDistribution() {
        return AjaxResult.success(encyclopediaService.getEncyclopediaCategoryDistribution());
    }
} 